package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherService {

    public boolean addTeacher(Teacher tea) {
        TeacherDao teacherDao = new TeacherDao();
        return teacherDao.addTeacher(tea);
    }

    public boolean isExists(String id) {
        TeacherDao teacherDao = new TeacherDao();
        Teacher[] teac = teacherDao.findAllTeacher();
        boolean exists = false;
        for (int i = 0; i < teac.length; i++) {
            if (teac[i]!=null&&teac[i].getId().equals(id)){
                exists =true;
            }
        }
        return exists;
    }

    public Teacher[] findAllTeacher() {
        TeacherDao teacherDao = new TeacherDao();
        Teacher[] teachers = teacherDao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i]!=null){
                flag = true;
               break;
            }
        }
        if (flag){
            return teachers;
        }else {
            return null;
        }

    }

    public void deleteTeacher(String id) {
        TeacherDao teacherDao = new TeacherDao();
        teacherDao.deleteTeacher(id);
    }

    public void updateTeacher(String id, Teacher ter) {
        TeacherDao teacherDao = new TeacherDao();
        teacherDao.updateTeacher(id,ter);
    }
}
